package definite.Guide.Book.JColorChooser;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

public class ColorSamplePopup {

	private static JButton button;

	public static void main(String[] args) {
		Runnable r = new Runnable() {

			@Override
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				JFrame frame = new JFrame("Show Popup Color Chooser");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				button = new JButton("Pick to change background");
				ActionListener action = new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						Color init = button.getBackground();
						Color theNew =
							JColorChooser.showDialog(null,
									"Change Button BackGround", init);
						if (theNew != null)
							button.setBackground(theNew);
					}
				};
				button.addActionListener(action);

				frame.add(button, BorderLayout.CENTER);
				frame.setLocationRelativeTo(null);
				frame.setSize(300, 100);
				frame.setVisible(true);
			}
		};

		EventQueue.invokeLater(r);
	}
}
